/*
 * Copyright (c) 2017. 深圳一七科技. All rights reserved.
 */

package com.yiqi.liebang.feature.news.presenter;

import com.yiqi.liebang.entity.bo.OrderBo;
import com.yiqi.liebang.entity.bo.PageBo;
import com.yiqi.liebang.entity.bo.VisitorBo;
import com.yiqi.liebang.feature.news.contract.VisitorContract;
import com.yiqi.liebang.feature.news.dependencies.visitor.DaggerVisitorPresenterComponent;
import com.yiqi.liebang.feature.order.contract.OrderContract;
import com.yiqi.liebang.feature.order.dependencies.order.DaggerOrderPresenterComponent;

import java.util.List;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * LIJUWEN
 *
 * @email yiyayiyayaoljw@gmail.com
 * @date 2018/7/11 9:31
 */
public class VisitorPresenter implements VisitorContract.Presenter {

    private VisitorContract.View mView;

    @Inject

    VisitorContract.Model mModel;


    public VisitorPresenter(VisitorContract.View mView) {
        this.mView = mView;
        DaggerVisitorPresenterComponent.create().inject(this);
    }

    @Override
    public void start() {

    }



    @Override
    public void getVisitorList(int pageIndex, int pageSize) {
        mModel.getVisitorList(new PageBo(pageIndex, pageSize))
                .compose(mView.bindToLife()).subscribe(new Observer<List<VisitorBo>>() {
            @Override
            public void onSubscribe(Disposable d) {
//                mView.showLoading(d);
            }

            @Override
            public void onNext(List<VisitorBo> couponBoPageData) {
                if (couponBoPageData!=null&&couponBoPageData.size()>0){
                    mView.showVisitorListSuccess(couponBoPageData);
                }else {
                    mView.showVisitorListEmpty();
                }
//                mView.dismissLoading();
            }

            @Override
            public void onError(Throwable e) {
//                mView.dismissLoading();
                mView.showVisitorListError(e.getMessage());
            }

            @Override
            public void onComplete() {
//                mView.dismissLoading();
            }
        });
    }

    @Override
    public void getVisitorListMore(int pageIndex, int pageSize) {
        mModel.getVisitorList(new PageBo(pageIndex, pageSize))
                .compose(mView.bindToLife()).subscribe(new Observer<List<VisitorBo>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(List<VisitorBo> couponBoPageData) {
                mView.showVisitorListMoreSuccess(couponBoPageData);
            }

            @Override
            public void onError(Throwable e) {
                mView.showVisitorListMoreError(e.getMessage());
            }

            @Override
            public void onComplete() {

            }
        });
    }
}
